﻿var currReserve;

function getCurrReserve() {
	return currReserve;
}

function getNewReserve(restaurant) {
	$.ajax({
		type: "POST",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		async: false,
		url: "Customer/getNewReserve",
		data: JSON.stringify(restaurant),
		success: function (reserve) {
			currReserve = reserve;

			OpenAddReserveWindow();
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});
}

function saveReserve() {
	var isOK;

	$.ajax({
		type: "POST",
		async: false,
		url: "Customer/saveReserve",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		data: JSON.stringify(getCurrReserve()),
		success: function (result) {
			isOK = result;
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});

	return isOK;
}

function validateReserve() {
	var isOK;

	$.ajax({
		type: "POST",
		async: false,
		url: "Customer/validateReserve",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		data: JSON.stringify(getCurrReserve()),
		success: function (result) {
			isOK = result;
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});

	return isOK;
}

function deleteReserve(reserveID) {
	$.ajax({
		async: false,
		url: "Customer/cancelReserve",
		data: {
			reserveID: reserveID
		},
		success: function (result) {
			isOK = result;
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});
}